function k = estimateK(I_rows, I_cols)
    T = 100;
    freq = round(I_cols/T);
%     I_rows = 1024;
%     I_cols = freq*T;
    std_sigma = [0 1 2 5 10 15 20];
%     std_sigma = [0 1 2];
    F = length(std_sigma);
    A = 0.5;
    B = 0.5;
    B1 = 0;
    noise_intensity = zeros(1,F);
    noise_mean_num = 0;
    gamma = 1;
    phase_shift = zeros(1,F);
    phase_shift_tilts = 0;
    dirName =['Figure', int2str(I_rows), int2str(I_cols)];
    mkdir(dirName);
    filepath = [dirName,'/I'];
    fun_createFigure(F, A, B, B1, freq, I_rows, I_cols, ...
            noise_intensity, noise_mean_num, gamma,...
    phase_shift, phase_shift_tilts, filepath);
    
    I = readImage(filepath, I_rows, I_cols, F);
    p = zeros(1,F);
    for f = 1:F
        I(:,:,f) = I(:,:,f) + std_sigma(f)*randn(I_rows,I_cols);
        ftf = I(:,:,f)'*I(:,:,f);
        [~,S,~] = svd(ftf);
        p(f) = trace(sqrt(S))/I_cols; %取相应秩大小的矩阵奇异值计算
    end
    k = (F*sum(std_sigma.*p) - sum(std_sigma)*sum(p))/(F*sum(std_sigma.^2)-sum(std_sigma)^2);
    save('k.mat','k');
end


function I = readImage(filePath, I_rows, I_cols, F)
    img_path_list = dir(strcat(filePath,'*.bmp'));
    %dir 列出当前文件夹中的文件信息
    img_num = length(img_path_list);%获取图像总数量
    I = zeros(I_rows, I_cols, F);
    if img_num > 0 %有满足条件的图像
        for f = 1 : (img_num) %逐一读取图像
            img_name = [filePath,'-',int2str(f),'.bmp'];
            img = imread(img_name);
%             fprintf("读取图片：%s \n",img_name);
%             figure;mesh(img);
            I(:, :, f) = double(img);
        end
        fprintf("-----------------读取完毕！---------------------- \n");
    else
        error("没有图像可以读取或读取文件名错误");
    end
    
end

